package sort;

/**
 * @description:
 * @author: walt-zhong
 * @createDate: 2021/3/8
 */
public class Insertion {
    public Insertion(){}

    public void sort(Comparable[] arr){
        for(int i = 0;i<arr.length-1;i++){
            for(int j=i+1;j<arr.length;j++){
                if(greater(arr[i],arr[j])){
                    swap(arr,i,j);
                }
            }
        }
    }

    public boolean greater(Comparable a,Comparable b){
        return a.compareTo(b)>0;
    }

    public void swap(Comparable []arr,int i,int j){
        Comparable temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}
